home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
038a
/
bas_int1.zip
/
FILEXIST.BAS
< prev
next >
Wrap
BASIC Source File
|
1991-02-17
|
5KB
|
106 lines
'==========================================================================
' DOS Interrupt File Exist Routine
' Written for QuickBASIC 4.5
' Randy Sharpe CIS 72425,1247
' December 12, 1989
'****************************************************************************
' Sample Main Program calling SUB DoesFileExist
'***************************************************************************
'
' You may eliminate this block by instead adding the metacommand:
' "$include qb.bi in your code, but it contains some extra goodies
' you probably won't need.
' If running within QuickBASIC environment, you must load quickbasic
' using "/l qb.qlb"; this will load the "quick library" version of
' qb.lib. When producing an exe file from OUTSIDE of QuickBASIC using
' bc and link, be sure to "link-in" QB.LIB. Typically, this is
' accomplished by typing the following on the LIBRARIES line when
' prompted by LINK:
'
' BCOM45 + QB (+ any other libs you may have)
' This will link in the necessary object code for CALL INTERRUPT.
' If producing an EXE from within QuickBASIC environment, all will
' be handled automatically.
TYPE RegType
ax AS INTEGER 'AH/AL regs
bx AS INTEGER 'BH/BL regs
cx AS INTEGER 'CH/CL regs
dx AS INTEGER 'DH/DL regs
bp AS INTEGER 'base pointer
si AS INTEGER 'source index reg
di AS INTEGER 'destination index reg
Flags AS INTEGER 'flags reg
END TYPE
DIM SHARED InRegs AS RegType, OutRegs AS RegType, True, False
DECLARE SUB DoesFileExist (FileExists!, FileName$)
DECLARE SUB INTERRUPT (IntNumber AS INTEGER, _
InRegs AS RegType, _
OutRegs AS RegType)
'-------------------------------------------------------------------------
CLS
INPUT "Please Enter File Name To Search For: ", FileName$
CALL DoesFileExist(FileExists!, FileName$)
IF FileExists! THEN
'CALL ReadFile(FileName$) 'call the file read routine
PRINT FileName$; " Found" 'test purposes
ELSE
'CALL FileNotFoundErrMsg(FileName$) 'call the error message routine
PRINT FileName$; " Not Found" 'test purposes
END IF
'==========================================================================
' DOS Interrupt File Exist Routine
' Written for QuickBASIC 4.5
' Randy Sharpe CIS 72425,1247
' December 12, 1989
'============================================================================
' Subroutine: DoesFileExist (FileExists!, FileName$)
'
' Input : File name to search for in FileName$. This filename may contain
' drive/path info, but will default to current if absent. It may
' also contain wildcard and pattern match chars "*" and "?".
' Process : Does a DOS INT21, service 4E to find the first occurence (if
' any) of file string contained in FileName$ in designated path &
' dir (if you need to find all occurences, you must continue
' all ensuing searches with INT21H, service 4FH). For a read, we
' want it to exist, but for a write, we want to give a message if
' it does exist to make sure user wants to overwrite it. For
' technical reference for this interrupt, see Microsoft Basic
' Language Reference.
' Output : Exist Boolean in FileExists
' Coupling : Called by Main
' Calls DOS Interrupt 21, service 4E
'
' Declare as follows:
' DECLARE SUB DoesFileExist (FileExists!, FileName$)
' DECLARE SUB INTERRUPT (IntNumber AS INTEGER, _
' InRegs AS RegType, _
' OutRegs AS RegType)
'============================================================================
SUB DoesFileExist (FileExists!, FileName$)
IntFileName$ = FileName$ + CHR$(0)
InRegs.ax = &H4E00
InRegs.dx = SADD(IntFileName$)
InRegs.cx = &H0
CALL INTERRUPT(&H21, InRegs, OutRegs)
CarryFlag& = (OutRegs.Flags AND &H1)
FileExists! = CarryFlag& - 1 'File exists if FileExists! = -1
'File does not exist if it = 0
END SUB